package platform

import (
	"github.com/gogf/gf/v2/container/gmap"
	"github.com/wzh200x/hyperNexus/hyperNexusType"
)

type PlatformHelper struct {
	Platform *gmap.StrAnyMap
}

func (p *PlatformHelper) RegisterPlatform(platform IPlatform) {
	p.Platform.Set(hyperNexusType.GetPlatformName(platform.GetPlatformID()), platform)
}

func (p *PlatformHelper) GetPlatform(platformType int32) IPlatform {
	platform := p.Platform.Get(hyperNexusType.GetPlatformName(int(platformType)))
	if platform == nil {
		return nil
	}
	return platform.(IPlatform)
}

func (p *PlatformHelper) Init() {
	p.InitPlatform()
}

func (p *PlatformHelper) InitPlatform() {
	p.RegisterPlatform(NewPlatformWechat())
	p.RegisterPlatform(NewPlatformAlipay())
	p.RegisterPlatform(NewPlatformByteJump())
	p.RegisterPlatform(NewPlatformKuaiShou())
	p.RegisterPlatform(NewPlatformVivo())
	p.RegisterPlatform(NewPlatformOppo())
}

func NewPlatformHelper() *PlatformHelper {
	return &PlatformHelper{
		Platform: gmap.NewStrAnyMap(true),
	}
}
